import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';

import '../../api/interface/user_api.dart';
import '../../api/request/response_data.dart';
import '../../config/const.dart';
import '../../widget/common_widget.dart';

class MinAgreeDialog extends StatefulWidget {
  final Function sure;
  final Function cancel;
  final Map user;
  const MinAgreeDialog({super.key, required this.sure, required this.cancel, required this.user});

  @override
  State<MinAgreeDialog> createState() => _MinAgreeDialogState();
}

class _MinAgreeDialogState extends State<MinAgreeDialog> {


  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  _invite(String status)async{
    Map<String,dynamic> data = {
      'status':status,
      'userId':widget.user['parent_id']
    };
    showLoading();
    ResponseData res = await UserAPI.invitationAgree(data);
    hideLoading();
    if(res.code == 200){
     if(status == '1'){
       widget.sure();
     }else{
       widget.cancel();
     }
     SmartDialog.dismiss();
    }

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      body: GestureDetector(
        onTap: (){
          FocusScope.of(context).requestFocus(FocusNode());
        },
        child: Container(
          color: Colors.transparent,
          width: 1.sw,
          height: 1.sh,
          alignment: Alignment.center,
          child: Container(
            width: 680.w,
            padding: EdgeInsets.symmetric(horizontal: 40.w),
            decoration: BoxDecoration(
                color: Color(0xff1e1d20),
                borderRadius: BorderRadius.circular(16.w)
            ),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Container(
                  height: 112.w,
                  decoration: BoxDecoration(
                      border: Border(bottom: BorderSide(color: Color.fromRGBO(255, 255, 255, 0.1),width: 1.w))
                  ),
                  child: Stack(
                    children: [
                      Container(
                        height: 112.w,
                        alignment: Alignment.center,
                        child: Text('Invitation Request'.tr,style: TextStyle(
                            color: Colors.white,
                            fontSize: 32.sp,
                            fontWeight: FontWeight.w600
                        ),),
                      ),
                      Positioned(child: GestureDetector(
                        onTap: (){
                          _invite('0');
                        },
                        child: Container(
                          padding: EdgeInsets.only(top: 24.w,),
                          child: Image.asset('assets/common/common_close.png',width: 48.w,),
                        ),
                      ),top: 0,right: 0,)
                    ],
                  ),
                ),
                Container(
                  margin: EdgeInsets.symmetric(vertical: 40.w),
                  alignment: Alignment.center,
                  child: Text('You have received an invitation for administrative privileges. Please confirm whether to join the privileges.'.tr,style: TextStyle(
                      color: Colors.white,
                      fontSize: 24.sp,
                      fontWeight: FontWeight.w400
                  ),),
                ),
                Container(
                  alignment: Alignment.center,
                  margin: EdgeInsets.only(bottom: 40.w),
                  child: Text('Invitation email:  ${widget.user['email']??''}'.tr,style: TextStyle(
                      color: Colors.white,
                      fontSize: 24.sp,
                      fontWeight: FontWeight.w400
                  ),),
                ),
                Container(
                  height: 108.w,
                  child:  Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Expanded(child: GestureDetector(
                        onTap: (){
                          _invite('0');
                        },
                        child: Container(
                          child: Text('Cancel'.tr,style: TextStyle(
                              color: Colors.white,
                              fontSize: 28.sp
                          ),),
                          decoration: BoxDecoration(
                              color:  themeDisableColor,
                              borderRadius: BorderRadius.circular(8.w)
                          ),
                          height: 108.w,
                          alignment: Alignment.center,
                        ),
                      )),
                      SizedBox(width: 40.w,),
                      Expanded(child: GestureDetector(
                        onTap: (){
                          _invite('1');
                        },
                        child: Container(
                          child: Text('Continue'.tr,style: TextStyle(
                              color: Colors.white,
                              fontSize: 28.sp
                          ),),
                          decoration: BoxDecoration(
                              color: themeColor,
                              borderRadius: BorderRadius.circular(8.w)
                          ),
                          height: 108.w,
                          alignment: Alignment.center,
                        ),
                      )),
                    ],
                  ),
                ),
                SizedBox(height: 40.w,),
              ],
            ),
          ),
        ),
      ),
    );
  }

}
